package com.region.http.client.core;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author liujieyu
 * @date 2023/6/10 17:22
 * @desciption
 */
public class RegionClientProxy implements InvocationHandler {

    private ClientProxyHandler clientProxyHandler;

    public RegionClientProxy(ClientProxyHandler clientProxyHandler) {
        super();
        this.clientProxyHandler = clientProxyHandler;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (Object.class.equals(method.getDeclaringClass())) {
            // If it's a method of the object class just run it
            return method.invoke(this, args);
        } else {
            return clientProxyHandler.invokeObject(method, args);
        }
    }
}
